package com.hp.jus.core.impl;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.net.URL;
import java.util.Properties;


public class PropertiesJusImpl extends JusImpl{
	
	private String fileLocation;
	private Properties dataStore;

	@Override
	public Boolean add(String key, URL url)throws Exception {
		dataStore.put(key, url.toString());
		return true;
	}

	@Override
	public Boolean remove(String key)throws Exception {
		dataStore.remove(key);
		return true;
	}

	@Override
	public Boolean update(String key, URL url)throws Exception {
		dataStore.put(key, url.toString());
		return true;
	}

	@Override
	public URL get(String key)throws Exception {
		return new URL(dataStore.get(key).toString());
	}

	@Override
	public void init()throws Exception {
		fileLocation = props.getProperty("impl.class.file.location");
		dataStore = new Properties();
		File file = new File(fileLocation);
		if(file.exists()){
			dataStore = new Properties();
			dataStore.load(new FileInputStream(file));
		}
	}

	@Override
	public void close() throws Exception {
		dataStore.store(new FileOutputStream(fileLocation), null);
	}
}
